<template>
  <!--会签管理-我的提交-劳务结算编辑弹窗-->
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    okText="提交"
  >
    <template v-if="pageType === 'edit'">
      <wt-naowubianji-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit"></wt-naowubianji-form>
    </template>
    <template v-else-if="pageType === 'anew'">
      <a-tabs type="card" @change="callback">
        <a-tab-pane key="1" tab="重新提交">
           <wt-naowubianji-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit"></wt-naowubianji-form>
        </a-tab-pane>
        <a-tab-pane key="2" tab="查看上次审核记录">
          <wt-laowuxiang-form ref="realForm2"  :disabled="disableSubmit2"></wt-laowuxiang-form>
        </a-tab-pane>
      </a-tabs>
    </template>
    <template #footer>
      <a-button  key="back" @click="handleCancel">取消</a-button>
      <a-popconfirm v-if="pageType != 'anew'" title="确定保存吗？" @confirm="handleSave"><a-button key="save" type="primary" >保存</a-button></a-popconfirm>
      <a-popconfirm  title="确定提交吗？" @confirm="handleOk"><a-button key="submit" type="primary">提交</a-button></a-popconfirm>
    </template>
  </j-modal>
</template>

  <script>
import WtNaowubianjiForm from './WtNaowubianjiForm'
import WtLaowuxiangForm from './WtLaowuxiangForm'
export default {
  name: 'WtShenpiModal',

  components: {
    WtNaowubianjiForm,WtLaowuxiangForm
  },
  data() {
    return {
      title: '',
      width: 1000,
      visible: false,
      disableSubmit: false,
      disableSubmit2: false,
      privacyDialogShow: false,
      pageType: '', //anew-重复提交 edit-编辑
      objdata: {},
    }
  },
  methods: {
    callback(e) {
      console.log(1, e)
      if (e === '2') {
        this.$nextTick(() => {
          this.$refs.realForm2.edit(this.objdata);
          this.disableSubmit2 = true;
        })
      }
    },
    confirmPrivacy() {
      // console.log('同意了用户协议')
      // console.log(this.privacyDialogShow)l
      this.privacyDialogShow = false
      // console.log(this.privacyDialogShow)
    },
    cancelPrivacy() {
      // console.log('拒绝了用户协议')
      this.privacyDialogShow = false
    },
    add() {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.add()
      })
    },
    edit(record, type) {
      let that = this;
      this.objdata = record;
      if (!!type) {
        this.pageType = type;
      }
      this.visible = true;
      this.$nextTick(() => {
        this.$refs.realForm.edit(record, type);
      })
      this.$forceUpdate();
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.submitForm('1');
    },
    handleSave() {
      this.$refs.realForm.submitForm('0')
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>